#include <bits/stdc++.h>
using namespace std;
int T,n,m,L,V,p[100010],d[100010],v[100010],a[100010],use[100010];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>T;
    while(T--){
        cin>>n>>m>>L>>V;
        for(int i=1;i<=n;i++){
            cin>>d[i]>>v[i]>>a[i];
        }
        for(int i=1;i<=m;i++){
            cin>>p[i];
        }
        int cnt=0,close=0;
        for(int i=1;i<=n;i++){
            if(a[i]==0){
                if(v[i]>V&&d[i]<p[m]){
                    cnt++;
                }
            }else if(a[i]>0){
                if(v[i]>V){
                    cnt++;
                    continue;
                }else{
                    double dis=(1.0*V*V-v[i]*v[i])/(2.0*a[i])+d[i];
                    for(int j=1;j<m;j++){
                        if(p[j]<=dis&&dis<=p[j+1]){
                            use[p[j]]=1;
                            cnt++;
                            break;
                        }
                    }
                }
            }else{
                if(v[i]<=V){
                    continue;
                }else{
                    double dis=(1.0*V*V-v[i]*v[i])/(2.0*a[i])+d[i];
                    //cout<<dis<<" ";
                    for(int j=1;j<=m;j++){
                        if(d[i]<=p[j]&&p[j]<=dis){
                            use[p[j]]=1;
                            cnt++;
                            break;
                        }
                    }
                }
            }
            //cout<<cnt<<" ";
        }
        cout<<cnt<<" ";
        bool f=0;
        for(int i=1;i<=n;i++){
            if(a[i]==0){
                for(int j=1;j<=m;j++){
                    if(d[i]<=p[j]&&use[p[j]]){
                        f=1;
                        break;
                    }
                }
                if(f){
                    break;
                }
            }
        }
        if(!f){
            close=1;
        }
        for(int i=1;i<=L;i++){
            if(use[i]){
                close++;
            }
        }
        cout<<m-close;
    }
    return 0;
}
